package com.frank.controller;


import com.frank.dto.CommonListDto;
import com.frank.dto.JobDto;
import com.frank.dto.JsonResult;
import com.frank.dto.QueryPageDto;
import com.frank.model.Job;
import com.frank.model.JobRecord;
import com.frank.service.RecruitManageService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import java.util.List;

import javax.annotation.Resource;

@RestController
@RequestMapping("/recruit")
public class RecruitManageController {
    @Resource
    private RecruitManageService recruitManageService;

    @RequestMapping(value = "/getRecruitList", method = RequestMethod.POST)
    public JsonResult<?> getRecruitList(@RequestBody QueryPageDto queryPageDto) {
       CommonListDto commonListDto = recruitManageService.getRecruitList(queryPageDto);
        return new JsonResult<>(200,"获得招聘计划成功",commonListDto);
    }


    @RequestMapping(value = "/getJobList", method = RequestMethod.GET)
    public JsonResult<?> getJobRecruitListByType(@RequestParam("recruit_type") String recruit_type) {
        List<Job> jobList = recruitManageService.getJobRecruitListByType(recruit_type);
        return new JsonResult<>(200,"获得工作列表成功",jobList);
    }

    @Transactional
    @RequestMapping(value = "/addRecruitPlan", method = RequestMethod.POST)
    public JsonResult<?> addRecruitPlan(@RequestBody JobDto jobDto) {
        if (recruitManageService.addRecruitPlan(jobDto)){
            return new JsonResult<>(200,"新增招聘计划成功");
        }else {
            return new JsonResult<>(500,"新增招聘计划失败");
        }
    }

    @Transactional
    @RequestMapping(value = "/modifyRecruit", method = RequestMethod.POST)
    public JsonResult<?> modifyRecruit(@RequestBody JobDto jobDto) {
        if (recruitManageService.modifyRecruit(jobDto)){
            return new JsonResult<>(200,"修改招聘计划成功");
        }else {
            return new JsonResult<>(500,"修改招聘计划失败");
        }
    }

    @Transactional
    @RequestMapping(value = "/deleteRecruit", method = RequestMethod.POST)
    public JsonResult<?> deleteRecruit(@RequestParam("jobId") Integer jobId) {
        if (recruitManageService.deleteRecruit(jobId)){
            return new JsonResult<>(200,"删除招聘计划成功");
        }else {
            return new JsonResult<>(500,"删除招聘计划失败");
        }
    }

}
